// 公共方法
export default {
    // 判空处理
    isEmpty: (form) => {
        var bool = false
        for (var key in form) {
            var str = typeof form[key]
            if (form.hasOwnProperty(key)) {
                form[key] = str == "string" ? form[key].trim() : form[key];
                if ((form[key] == "" || form[key] == null || form[key] == "undefined") && form[key] !== 0) {
                    bool = true
                }
            }
        }
        return bool
    },
    // 删除&全部删除
    delete: function (url, index, ids, callback) {
        this.$confirm("确定要删除吗？", "提示", {
            type: "warning"
        })
            .then(() => {
                this.$axios
                    .delete(url, { data: ids })
                    .then(({ data: res }) => {
                        if (res.code != 0) {
                            return this.$message.error(res.msg);
                        }
                        this.$message.success("删除成功");
                        this.tableData.splice(index, 1);
                        this.ids = []
                        this.multipleSelection = [];
                        callback({})

                    })
                    .catch(err => {
                        return this.$message.error(err.message);
                    });
            })
            .catch(() => { });
    },
    singleDelete: function (url, index, id, callback) {
        this.$confirm("确定要删除吗？", "提示", {
            type: "warning"
        })
            .then(() => {
                this.$axios
                    .delete(url + id)
                    .then(({ data: res }) => {
                        if (res.code !== 0) {
                            return this.$message.error(res.msg);
                        }
                        this.$message.success("操作成功");
                        callback({})
                    })
                    .catch(() => { });
            })
            .catch(() => { });
    }
} 